package day07_14.day07;

import java.util.Scanner;

public class Main01 {
    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        int N = scn.nextInt();
        int count = 0;
        while (fib(count) < N){
            count ++;
        }
        int z1 = fib(count);
        int z2 = fib(count -1);
        System.out.println(Math.min(Math.abs(z1 - N) , Math.abs(N - z2)));
    }
    public static int fib( int i){
        if (i == 0){
            return 0;
        }
        if (i == 1){
            return 1;
        }
        return fib(i - 1) + fib(i - 2);
    }
}
